package com.ruoyi.project.business.controlcenter.iot.manager;

import com.ruoyi.project.business.controlcenter.iot.constant.CommonConstant;
import com.ruoyi.project.business.controlcenter.iot.mqtt.manager.MqttSendManager;
import com.ruoyi.project.business.controlcenter.iot.util.MqttParamUtil;
import com.ruoyi.project.business.controlcenter.iot.util.TopicUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class IotManager {

    @Resource
    private MqttSendManager mqttSendManager;

//    @Resource
//    private IotUserDeviceService userDeviceService;

    public void operateIndex(Integer index, String mac, Integer onOff) {
        String params = MqttParamUtil.getParams(index, mac, onOff, "pin");
        String topic = TopicUtil.extractTopic();
        mqttSendManager.sendToMqtt(topic, CommonConstant.QOS.ONLY_ONCE, params);
    }

    public void blink(Integer index, String mac, Integer onOff) {
        String params = MqttParamUtil.getParams(index, mac, onOff, "blink");
        String topic = TopicUtil.extractTopic();
        mqttSendManager.sendToMqtt(topic, CommonConstant.QOS.ONLY_ONCE, params);
    }

    public void blinkPwm(Integer index, String mac, Integer pmw) {
        String params = MqttParamUtil.getBlinkPwmParams(index, mac, pmw);
        String topic = TopicUtil.extractTopic();
        mqttSendManager.sendToMqtt(topic, CommonConstant.QOS.ONLY_ONCE, params);
    }

//    public void pwm(Integer index, String mac, Integer pmw) {
//        String params = MqttParamUtil.getPwmParams(index, mac, pmw);
//        String topic = TopicUtil.extractTopic();
//        mqttSendManager.sendToMqtt(topic, CommonConstant.QOS.ONLY_ONCE, params);
//    }
//
//    public void pwmOff(Integer index, String mac) {
//        String params = MqttParamUtil.getPwmOffParams(index, mac);
//        String topic = TopicUtil.extractTopic();
//        mqttSendManager.sendToMqtt(topic, CommonConstant.QOS.ONLY_ONCE, params);
//    }

    /**
     *
     * @param mac
     * @param reqType
     * @param seconds 执行时间
     */
//    public void deviceBleOperate(String mac, String reqType, Integer seconds) {
//        String params = MqttParamUtil.getBleAdvParam(mac, reqType, seconds);
//        String topic = TopicUtil.extractTopic();
//        mqttSendManager.sendToMqtt(topic, CommonConstant.QOS.ONLY_ONCE, params);
//    }


//    public void saveDeviceStorage(String ssid, String pwd, Long userDeviceId, Long userId) {
//        IotUserDevice device = userDeviceService.findById(userDeviceId, userId);
//        if(device == null) {
//            throw new ServiceException(ErrorCodeConstants.UNKNOWN_USER_DEVICE);
//        }
//        String params = MqttParamUtil.getSaveWifiParams(ssid, pwd, device.getMac());
//        String topic = TopicUtil.extractTopic();
//        mqttSendManager.sendToMqtt(topic, CommonConstant.QOS.ONLY_ONCE, params);
//    }


//    public void deviceBleCancel(String mac) {
//        String params = MqttParamUtil.getBleAdvCancelParam(mac);
//        String topic = TopicUtil.extractTopic();
//        mqttSendManager.sendToMqtt(topic, CommonConstant.QOS.ONLY_ONCE, params);
//    }
}
